package com.huizhonglm.diap.presenters.wallet;

import com.alibaba.fastjson.JSON;
import com.bruce.common.utils.EmptyUtil;
import com.huizhonglm.diap.api.API;
import com.huizhonglm.diap.api.HttpCallback;
import com.huizhonglm.diap.api.model.wallet.RcmRevenueOldParams;
import com.huizhonglm.diap.api.model.wallet.RevenueInfoOld;
import com.huizhonglm.diap.presenters.BasePresenter;
import com.huizhonglm.diap.ui.wallet.iView.RcmRevenueOldIView;

import java.util.List;

/**
 * 描述当前类的作用
 *
 * @author LiXiaoLong
 * @version 1.0
 * @since 2016-03-07 13:53
 */
public class RcmRevenueOldPresenter extends BasePresenter {

    private RcmRevenueOldIView iView;

    public RcmRevenueOldPresenter(RcmRevenueOldIView iView) {
        this.iView = iView;
 }

    public void loadData(String userId){
        RcmRevenueOldParams params = new RcmRevenueOldParams();
        params.userId = userId;
        API.http().post("rcmRevenue", params, new HttpCallback() {
            @Override
            public void onSuccess(String result) {
                if (!EmptyUtil.isEmpty(result)) {
                    List<RevenueInfoOld> list = JSON.parseArray(result, RevenueInfoOld.class);
                    if (!EmptyUtil.isEmpty(list)) {
                        iView.onLoadDataSuccess(list);
                    } else {
                        iView.onLoadDataSuccess(null);
                    }
                } else {
                    iView.onLoadDataSuccess(null);
                }
            }

            @Override
            public void onFailure(Throwable ex) {
                iView.onLoadDataFailure();
            }
        });
    }
}
